package table

import (
	"i18n-template/components"

	"gorm.io/gorm"
)

type Index struct {
	gorm.Model
	Language    string `json:"language" gorm:"type:text;size:128;comment:语言"`
	Swiper      string `json:"swiper" gorm:"type:text;comment:轮播图"`
	SidePicture string `json:"sidePicture" gorm:"type:text;comment:侧边栏图片"`
	Rich        string `json:"rich" gorm:"comment:富文本"`
}

func (i Index) TableName() string {
	return "index"
}

func (i Index) FindIndexByLang(I Index) (e Index, err error) {
	index := Index{}
	err = components.DB.Model(&Index{}).Where("language = ?", I.Language).First(&index).Error
	return index, err
}

func (i Index) GenerateIndex(I Index) error {
	return components.DB.Model(&Index{}).Save(&I).Error
}

func (i Index) UpdateIndexByLang(I Index) {
	components.DB.Model(&Index{}).Where("language = ?", I.Language).Updates(I)
}
